package com.school.lab.common.utils;


import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * This class implements the ApplicationContextAware interface. The interface is
 * defined by SpringFramework. We implements this interface to get the reference
 * to spring ApplicationContext. This class will be used in GenericDao to
 * retrieve the bean defined in applicationContext.xml file according to the
 * bean name or id.
 * 
 * 
 */

public class SpringContextUtils implements ApplicationContextAware {

	private static ApplicationContext ctx;

	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		ctx = applicationContext;

	}

	public static ApplicationContext getCtx() {
		return ctx;
	}

	public static void setCtx(ApplicationContext ctx) {
		SpringContextUtils.ctx = ctx;
	}

	public static Object getBean(String beanName) {
		return getCtx().getBean(beanName);
	}

}

